package com.ayf.payment.game.api.service.payment.huyu.util;

import com.ayf.payment.game.api.utils.MD5Util;
import com.swwx.charm.commons.lang.utils.LogPortal;
import org.apache.commons.lang.StringUtils;

import java.util.Map;

public final class HuYuSignUtil {

    public static String getSign(String traceId, String methodName, Map<String, String> reqParam, String key) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : reqParam.entrySet()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
        }
        String signOriginStr = sb.append("key=").append(key).toString();
        LogPortal.info("{} {} 签名原文:{}",traceId,methodName,signOriginStr);
        String sign = MD5Util.strToMd52(signOriginStr);
        if (StringUtils.isEmpty(sign)) {
            return null;
        }
        sign = sign.toLowerCase();
        LogPortal.info("{} {} 实际签名:{}",traceId,methodName,sign);
        return sign;
    }


}
